MTB_robot coppeliasim <<
Previous Next >> MTB_robot add IK
MTB_robot add suction pad
在coppeliaSim裡的MTB_robot增加吸盤控制。(使用老師的程式)
W16_exam.7z
主程式
function sysCall_init()
-- do some initialization here
axis1=sim.getObjectHandle('MTB_axis1')
axis1=sim.getObjectHandle('MTB_axis1')
axis3=sim.getObjectHandle('MTB_axis3')
axis4=sim.getObjectHandle('MTB_axis4')
suctionPad=sim.getObjectHandle('suctionPad')
rotation1 = 0
distance3 = 0
deg = math.pi/180
--sim.sJointTargetVelocity(joint,5.5)
end
function sysCall_actuation()
calibration = 0.0042
message,auxiliaryData=sim.getSimulatorMessage()
if (message==sim.message_keypress) then
print(auxiliaryData[1])--key
if (auxiliaryData[1]==string.byte(' ')) then
end
if (auxiliaryData[1]==97) then--a
rotation1 = rotation1 + 5*deg
sim.setJointPosition(axis1, rotation1)
end
if (auxiliaryData[1]==100) then --d
rotation1 = rotation1 - 5*deg
sim.setJointPosition(axis1, rotation1)
end
if (auxiliaryData[1]==119) then --s
distance3 = distance3 + 0.01 + calibration
sim.setJointPosition(axis3, distance3)
end
if (auxiliaryData[1]==115) then --w
distance3 = distance3 - 0.01 - calibration
sim.setJointPosition(axis3, distance3)
end
if (auxiliaryData[1]==112) then --p activate the suction pad
sim.setScriptSimulationParameter(sim.getScriptAssociatedWithObject(suctionPad),'active','true')
end -- if p
if (auxiliaryData[1]==113) then --q deactivate the suction pad
sim.setScriptSimulationParameter(sim.getScriptAssociatedWithObject(suctionPad),'active','false')
end -- if q
end
end
function sysCall_sensing()
-- put your sensing code here
end
function sysCall_cleanup()
-- do some clean-up here
end
-- See the user manual or the available code snippets for additional callback functions and details
吸盤程式
function sysCall_init()
s=sim.getObjectHandle('suctionPadSensor')
l=sim.getObjectHandle('suctionPadLoopClosureDummy1')
l2=sim.getObjectHandle('suctionPadLoopClosureDummy2')
b=sim.getObjectHandle('suctionPad')
suctionPadLink=sim.getObjectHandle('suctionPadLink')
infiniteStrength=sim.getScriptSimulationParameter(sim.handle_self,'infiniteStrength')
maxPullForce=sim.getScriptSimulationParameter(sim.handle_self,'maxPullForce')
maxShearForce=sim.getScriptSimulationParameter(sim.handle_self,'maxShearForce')
maxPeelTorque=sim.getScriptSimulationParameter(sim.handle_self,'maxPeelTorque')
sim.setLinkDummy(l,-1)
sim.setObjectParent(l,b,true)
m=sim.getObjectMatrix(l2,-1)
sim.setObjectMatrix(l,-1,m)
end
function sysCall_cleanup()
sim.setLinkDummy(l,-1)
sim.setObjectParent(l,b,true)
m=sim.getObjectMatrix(l2,-1)
sim.setObjectMatrix(l,-1,m)
end
function sysCall_sensing()
parent=sim.getObjectParent(l)
if (sim.getScriptSimulationParameter(sim.handle_self,'active')==false) then
if (parent~=b) then
sim.setLinkDummy(l,-1)
sim.setObjectParent(l,b,true)
m=sim.getObjectMatrix(l2,-1)
sim.setObjectMatrix(l,-1,m)
end
else
if (parent==b) then
-- Here we want to detect a respondable shape, and then connect to it with a force sensor (via a loop closure dummy dummy link)
-- However most respondable shapes are set to "non-detectable", so "sim.readProximitySensor" or similar will not work.
-- But "sim.checkProximitySensor" or similar will work (they don't check the "detectable" flags), but we have to go through all shape objects!
index=0
while true do
shape=sim.getObjects(index,sim.object_shape_type)
if (shape==-1) then
break
end
if (shape~=b) and (sim.getObjectInt32Parameter(shape,sim.shapeintparam_respondable)~=0) and (sim.checkProximitySensor(s,shape)==1) then
-- Ok, we found a respondable shape that was detected
-- We connect to that shape:
-- Make sure the two dummies are initially coincident:
sim.setObjectParent(l,b,true)
m=sim.getObjectMatrix(l2,-1)
sim.setObjectMatrix(l,-1,m)
-- Do the connection:
sim.setObjectParent(l,shape,true)
sim.setLinkDummy(l,l2)
break
end
index=index+1
end
else
-- Here we have an object attached
if (infiniteStrength==false) then
-- We might have to conditionally beak it apart!
result,force,torque=sim.readForceSensor(suctionPadLink) -- Here we read the median value out of 5 values (check the force sensor prop. dialog)
if (result>0) then
breakIt=false
if (force[3]>maxPullForce) then breakIt=true end
sf=math.sqrt(force[1]*force[1]+force[2]*force[2])
if (sf>maxShearForce) then breakIt=true end
if (torque[1]>maxPeelTorque) then breakIt=true end
if (torque[2]>maxPeelTorque) then breakIt=true end
if (breakIt) then
-- We break the link:
sim.setLinkDummy(l,-1)
sim.setObjectParent(l,b,true)
m=sim.getObjectMatrix(l2,-1)
sim.setObjectMatrix(l,-1,m)
end
end
end
end
end
end
教學影片:
如何在cippeliasim裡的MTB_robot安裝吸盤。
W16_t.7z
MTB_robot coppeliasim <<
Previous Next >> MTB_robot add IK